//引入菠萝api
import { reqattrInfoList,reqattrInfoList2, reqattrInfoList3 } from '@/api/product/attrlnfoList'
import { defineStore } from 'pinia'

//引入接口函数，接口
import type {classificationS} from '@/api/model/spu'
//创建模块对象

export const useCategoryListStore = defineStore('categoryList', {
  state: () => {
    return {
      //一下三个属性用于收集用户真正选择的分类的id

      category1Id: <number|undefined>undefined,
      category2Id:<number|undefined> undefined,
      category3Id:<number|undefined> undefined,
      
      //以下三个数组用于存储服务器响应回来的分类数据

      category1List:<classificationS>[],
      category2List:<classificationS>[],
      category3List:<classificationS>[],
      


    }
  }
  ,
      actions: {
       //获取一级分类数据
        async reqattrInfoListDate()
        {
          const result = await reqattrInfoList()
          console.log('一级分类', result)
          
          this.category1List = result
        },
       //获取二级分类数据
        async reqattrInfoListDate2(id:number)
        {
          //给一级框赋值一级传给二级的id
          this.category1Id = id
          //当一级id一发生变化就给二级三级清空
          this.category2Id=undefined
            this.category3Id = undefined
            
          const result = await reqattrInfoList2(id)
          console.log('二级分类', result)
          
          this.category2List = result
        },
       //获取三级分类数据
        async reqattrInfoListDate3(id:number)
        {
          this.category2Id = id

          this.category3Id = undefined
          const result = await reqattrInfoList3(id)
          console.log('三级分类', result)
          
          this.category3List = result
        },
  },
     //菠萝计算属性 
  getters: {
        
      }
})